{extend name="platform/base" /}
{block name="resources"/}
<style type="text/css">

</style>
{/block}
{block name="main"}

<div class="row padder-v">
    <div class="col-sm-9" style="width:73%;">
        <a href="PLATFORM_MAIN/activity/addFightgroup" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> 添加拼团 </a>
    </div>
</div>
<section class="panel panel-default">
    <div class="table-responsive">
        <table class="table table-striped b-t b-light text-sm">
            <thead>
            <tr>
                <th width="20"><input type="checkbox"></th>
                <th class="center">排序</th>
                <th class="center">拼团名称</th>
                <th class="center">拼团宣传图片</th>
                <th class="center">拼团介绍</th>
                <th class="center">拼团定金占比</th>
                <th class="center">拼团商品折扣</th>
                <th class="center">拼团所需人数</th>
                <th class="center">开始时间</th>
                <th class="center">结束时间</th>
                <th class="center">状态</th>
                <th class="center">操作</th>

            </tr>
            </thead>
            <tbody id="list">
            <tr></tr>
            </tbody>
        </table>
    </div>
    {include file="platform/page" /}
</section>

{/block}
{block name="script"}

<script type="text/javascript">
    $(function(){
        LoadingInfo(1);
    });
    function LoadingInfo(page_index) {
        $.ajax({
            type : "post",
            url : "{:__URL('PLATFORM_MAIN/activity/fightgroupList')}",
            async : true,
            data : {
                "page_index" : page_index,
            },
            success : function(data) {
//                alert(JSON.stringify(data));
                var html = '';
                $("#total_count_num").text(data["total_count"]);
                $("#page_count_num").text(data["page_count"]);
                $("#page_count").val(data["page_count"]);
                $("#pageNumber a").remove();
                if (data["data"].length > 0) {
                    for (var i = 0; i < data["data"].length; i++) {
                        html += '<tr align="center">';
                        html += '<td><div class="cell"><label ><input name="sub" type="checkbox" value="'+ data['data'][i]["group_id"]+'" ></label></div></td>';
                        //<input type="text"  value="'+ data["data"][i]["level_name"]+'" level_id="'+ data['data'][i]['level_id']+'"  class="level_name">
                        html += '<td>'+ data['data'][i]["group_sort"] + '</td>';
                        html += '<td >'+ data['data'][i]["group_name"]+'</td>';
//                        html += '<td >'+ data[i]["msg_outline"]+'</td>';
                        if(data['data'][i]["group_banner"] == null || data['data'][i]["group_banner"] == '')
                        {
                            html += '<td></td>';
                        }else{
                            html += '<td><img src="__ROOT__/'+ data['data'][i]["group_banner"] +'" style="height:50px;"></td>';
                        }
                        html += '<td >'+ data['data'][i]["group_content"]+'</td>';
                        html += '<td >'+ data['data'][i]["deposit_money_rate"]+'</td>';
                        html += '<td >'+ data['data'][i]["group_discount"]+'</td>';
                        html += '<td >'+ data['data'][i]["max_number"]+'</td>';
                        html += '<td >'+ data['data'][i]["start_time"]+'</td>';
                        html += '<td >'+ data['data'][i]["end_time"]+'</td>';
                        if(data['data'][i]["group_state"] == 0){
                            html += '<td>关闭</td>';
                        }else if(data['data'][i]["group_state"] == 1){
                            html += '<td>开启</td>';
                        }else if(data['data'][i]["group_state"] == 2){
                            html += '<td>已开始</td>';
                        }else if(data['data'][i]["group_state"] == 3){
                            html += '<td>已结束</td>';
                        }else{
                            html += '<td></td>';
                        }
                        if(data['data'][i]["group_state"] == 0){
                            html += '<td><a href="javascript:deleteFightgroup('+data['data'][i]['group_id']+');">删除</a></td>';
                        }else if(data['data'][i]["group_state"] == 1){
                            html += '<td><a href="javascript:setFightgroupState('+data['data'][i]['group_id']+');">关闭</a><a href="'+__URL('PLATFORM_MAIN/activity/fightgroupDetail?group_id='+ data['data'][i]['group_id'] +'')+'">处理申请</a></td>';
                        }else if(data['data'][i]["group_state"] == 2){
                            html += '<td><a href="'+__URL('PLATFORM_MAIN/activity/fightgroupDetail?group_id='+ data['data'][i]['group_id'] +'')+'">处理申请</a></td>';
                        }else if(data['data'][i]["group_state"] == 3){
                            html += '<td></td>';
                        }
                        html += '</tr>';
                    }
                } else {
                    html += '<tr align="center"><th colspan="5">暂无符合条件的数据记录</th></tr>';
                }
                $("#list").html(html);
                var totalpage = $("#page_count").val();
                if (totalpage == 1) {
                    changeClass("all");
                }
                var $html = pagenumShow(jumpNumber,totalpage,{$pageshow});
                $("#pageNumber").append($html);

            }
        });
    }
    //全选
    function CheckAll(event){
        var checked = event.checked;
        $(".style0list tbody input[type = 'checkbox']").prop("checked",checked);
    }

    //删除拼团活动
    function deleteFightgroup(group_id){
        $.ajax({
            type : "post",
            url : "{:__URL('PLATFORM_MAIN/activity/delFightgroup')}",
            data : {
                'group_id' : group_id
            },
            success : function(data) {
                if (data['code'] > 0) {
                    showMessage('success', '删除成功');
                    location.href="{:__URL('PLATFORM_MAIN/activity/fightgroupList')}";
                } else {
                    showMessage('error', '删除失败');

                }
            }
        });
    }
    //设置拼团活动状态
    function setFightgroupState(group_id){
        $.ajax({
            type : "post",
            url : "{:__URL('PLATFORM_MAIN/activity/setPlatformFightgroupState')}",
            data : {
                'group_id' : group_id
            },
            success : function(data) {
                if (data['code'] > 0) {
                    showMessage('success', '关闭成功');
                    location.href="{:__URL('PLATFORM_MAIN/activity/fightgroupList')}";
                } else {
                    showMessage('error', '关闭失败');

                }
            }
        });
    }


</script>
{/block}